﻿using HalconDotNet;

namespace AntdUI_HamburgerMenuTabs.Pages
{
    public partial class Halcon : UserControl
    {
        private HImage ho_Image;

        public Halcon(string title, string path, string path2)
        {
            InitializeComponent();

            AntdUI.Panel panel = new()
            {
                Dock = DockStyle.Fill,
            };
            Controls.Add(panel);


        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 配置文件对话框,添加图像文件
            openFileDialog1.Title = "选择图像文件";
            openFileDialog1.Filter = "所有支持的图像|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff|" +
                                     "JPEG 图像|*.jpg;*.jpeg|" +
                                     "PNG 图像|*.png|" +
                                     "BMP 图像|*.bmp|" +
                                     "GIF 图像|*.gif|" +
                                     "TIFF 图像|*.tiff|" +
                                     "所有文件|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Multiselect = false;

            // 确认添加成功
            if (openFileDialog1.ShowDialog() == DialogResult.OK)  
            { 
                //获取用户选择的路径
                var imgUrl = openFileDialog1.FileName;
                //转换为Halcon图像
                ho_Image = new HImage(imgUrl);
                //在Halcon窗口显示
                hWindowControl1.HalconWindow.DispImage(ho_Image);

            }
        }
    }
}